package com.eshop.controller;

import com.eshop.commons.JResponse;
import com.eshop.commons.ParentController;
import com.eshop.commons.utils.MD5Utils;
import com.eshop.entity.Login;
import com.eshop.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController extends ParentController {
    @GetMapping("/retrieveAllUser")
    public JResponse retrieveUser(){
        List<User> users = userService.findAllUser();
        return JResponse.successful(userService.findAllUser());
    }

    @PostMapping("/login")
    public JResponse getById(@RequestBody Login login){
        User user  = userService.getUserByName(login.getUserName());
        String password1 = MD5Utils.getMD5(login.getPassword());
        String password2 = user.getPassword();
        if (password1.equalsIgnoreCase(password2)) {
            return JResponse.success("欢迎登录");
        }
        return JResponse.fail("账号密码不正确");
    }
}
